/*
   @Copyright:LintCode
   @Author:   tjyemail
   @Problem:  http://www.lintcode.com/problem/reverse-integer
   @Language: C++
   @Datetime: 16-02-09 05:16
   */

class Solution {
public:
	/**
	 * @param n the integer to be reversed
	 * @return the reversed integer
	 */
	int reverseInteger(int n) {
		// Write your code here
		long long a, f=(n>0);
		char str[32];
		sprintf(str,"%d",f?n:-n);
		reverse(str,str+strlen(str));
		sscanf(str,"%lld",&a);
		a = (f?a:-a);
		if (a>1L<<31-1 || a<-1L<<31) return 0;
		return a;
	}
};
